#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>

int
chrhexcmp(const char* n, const char* o)
{
	if (strlen(n) > strlen(o))
		return 1;
	else if (strlen(n) < strlen(o))
		return -1;
	else {
		int i = 0;
		while (i < strlen(n)) {
			if (toupper(n[i]) > toupper(o[i]))
				return 1;
			else if (toupper(n[i]) < toupper(o[i]))
				return -1;
			else
				++i;
		}
	}
	return 0;
}


int
main()
{
	unsigned long long number_min = 0, number_max = 0, number = 0;
	char n[102], max[102], min[102];
	freopen("maxhex.in", "r", stdin);
	freopen("maxhex.out", "w", stdout);
	memset(min, 0, sizeof(min));
	memset(max, 0, sizeof(max));
	while (scanf("%s", n) == 1) {
		if (chrhexcmp(n, max) > 0) {
			strcpy(min, max);
			strcpy(max, n);
		} else if (chrhexcmp(n, min) > 0) {
			strcpy(min, n);
		}
	}
	printf("%s %s\n", max, min);
	return 0;
}
